package com.gbx.day09;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

/**
 * Created by baoxing on 2016/12/01.
 * 最下
 */
public class Layout_1 extends FrameLayout{


    public Layout_1(Context context) {
        super(context);
    }

    public Layout_1(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public Layout_1(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {//分发
        Log.d("flag1","dispatchTouchEvent");
        return super.dispatchTouchEvent(ev);
    }
//view.getClipBounds()  rect
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {//打断
        Log.d("flag1","onInterceptTouchEvent");
        View view = getChildAt(0);
        Rect rect = new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
        if (!rect.contains((int) ev.getX(),(int) ev.getY())) {//不在子控件的范围内，返回true
            return true;
        }
        return super.onInterceptTouchEvent(ev);
    }

    //被父控件中断时会触发ACTION_CANCEL
    @Override
    public boolean onTouchEvent(MotionEvent event) {//触摸，
        Log.d("flag1","onTouchEvent：" + MotionEvent.actionToString(event.getAction()));
        return true;//如果返回true表示具备事件处理的能力,会执行：dispatchTouchEvent，onTouchEvent：ACTION_UP；false:则不会执行
    }
}
